//
// Created by nicemoe on 2021/7/31.
//

#include <iostream>
#include <cmath>

using namespace std;

int main()
{
    /**
     * 一维数组
     */
//    int a[] = {1, 2, 3, 4, 5, 6, 7, 8, 9};
//    int *p = a;
//    cout << *(p + 0) << p[0] << a[0] << *(a + 0) << endl;
//    cout << *(p + 1) << p[1] << a[1] << *(a + 1) << endl;
//    cout << *(p + 2) << p[2] << a[2] << *(a + 2) << endl;
//    cout << *(p + 3) << p[3] << a[3] << *(a + 3) << endl;
//
//    for (int i = 0; i < 9; ++i) {
//        cout << *(p + i);
//    }
//    cout << endl;
//    for (int i = 0; i < 9; ++i) {
//        cout << p[i];
//    }
//    cout << endl;
//    for (int i = 0; i < 9; ++i) {
//        cout << a[i];
//    }
//    cout << endl;
//    for (int i = 0; i < 9; ++i) {
//        cout << *(a + i);
//    }

/**
     * 二维数组
     */
    static int a[][3] = {{1, 2, 3},
                         {4, 5, 6}};
    //a + 1 时行指针  *(a + 1) 时列指针
    cout << a + 1 << *(a + 1) << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            cout << *(*(a + i) + j) << "\t";
        }
        cout << endl;
    }
    cout << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            cout << *(a[i] + j) << "\t";
        }
        cout << endl;
    }
    cout << endl;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            cout << a[i][j] << "\t";
        }
        cout << endl;
    }
    cout << "指向一维数组的指针变量一行指针" << endl;
    /*
     * p是行指针  p+1就到下一行
     * 以为数组指针变量维数和二维数组列数必须相同
     */
    int (*p)[3] = a;
    for (int i = 0; i < 2; ++i, p++) {
        for (int j = 0; j < 3; ++j) {
            cout << *(*p + j) << " ";
        }
        cout << endl;
    }

    int c[2][3][4]{
            {
                    {1,  2,  3,  4},
                    {5,  6,  7,  8},
                    {9,  10, 11, 12}
            },
            {
                    {13, 14, 15, 16},
                    {17, 18, 19, 20},
                    {21, 22, 23, 24}
            }
    };
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 4; ++k) {
                cout << *(*(*(c + i) + j) + k) << "\t";
            }
            cout << endl;
        }
        cout << endl;
    }
}
